/**
 * Belongs to WEF
 */


var allOption = [];
var flag=false;
function init(){
	var selOption= [];
	if(window.showModalDialog==null){
		allOption = window.opener.objWindow.allOption;
		selOption = window.opener.objWindow.selOption;
		document.getElementById("titleId").innerHTML=window.opener.objWindow.titleText;
	}else{
		allOption = window.dialogArguments.allOption;
		selOption = window.dialogArguments.selOption;
		document.getElementById("titleId").innerHTML=window.dialogArguments.titleText;
	}
	var opeOption =[];
	for(var i=0;i<allOption.length;i++){
		var bool = false; 
		for(var j=0;j<selOption.length;j++){
			if(allOption[i].textValue==selOption[j].textValue){
				selOption[j].value=allOption[i].value;
				bool = true;
				break;
			}
		}
		if(!bool)
			opeOption[opeOption.length] = allOption[i];
	}
	var valueFrom='right';
	if(window.showModalDialog==null){
		valueFrom=window.opener.objWindow.valueFrom;
	}else{
		valueFrom=window.dialogArguments.valueFrom;
	}
	if(valueFrom=='left'){
		DWRUtil.addOptions("typeNoSelId", selOption, 'value', 'textValue');
		DWRUtil.addOptions("typeSelId", opeOption, 'value', 'textValue');
	}else{
		DWRUtil.addOptions("typeNoSelId", opeOption, 'value', 'textValue');
		DWRUtil.addOptions("typeSelId", selOption, 'value', 'textValue');
	}
}
function add()
{
	var f = document.form1;
	var num=0;
	var length=f.s1.options.length;
	for(var i=0;i<length;i++){
	if(f.s1[i-num].selected){
		selectid = f.s1[i-num].index;
		num++;
 		if ((selectid)==-1)
 		{
 			window.alert("请选择要添加的项!!!");
 			return;
 		} 
 		for(var k=0;k<f.s2.options.length;k++)
 		{  
     		if (f.s2.options[k].value==f.s1.value )
     		{
      			window.alert("已存在此项!!!");
     	 		return;
    		}
 		}
 		text=f.s1[selectid].value;
  		var obj = new Option(f.s1[selectid].innerHTML,text);
  		f.s2.options.add(obj);
  		f.s1.remove(selectid);
	}
 	}
}


function remove(id)
{
	var f = document.form1;
 if(id=="s2")
 {
 	var length=f.s2.options.length;
	var num=0;
	for(var i=0;i<length;i++){
		if(f.s2[i-num].selected){
			selectid = f.s2[i-num].index;
			num++;
			if ((selectid)==-1)
			{
				window.alert("请选择一条要移除的项!!!");
				return;
			}
			var o=new Option(f.s2[selectid].innerHTML,f.s2[selectid].value);
			f.s1.options.add(o);
    		f.s2.remove(selectid);
		}
	}
 }
 else
 {
	if ((f.s1.selectedIndex)==-1)
	{
		window.alert("请选择一条要移除的项!!!");
		return;
	}
	val = f.s1.value;
    f.s1.options.remove(f.s1.selectedIndex); 

    for(var i = 0;i < f.s2.length; i++)
    {
		if(f.s2[i].value == val) 
		{
		f.s2.remove(i);
		break;
		}
    }
 }
}
function selectDoubleClick(selectid,type){
	var f = document.form1;
	if(type=='left'){
		var o=new Option(f.s1[selectid].innerHTML,f.s1[selectid].value);
		f.s2.options.add(o);
    	f.s1.remove(selectid);
	}else{
		var o=new Option(f.s2[selectid].innerHTML,f.s2[selectid].value);
		f.s1.options.add(o);
    	f.s2.remove(selectid);
	}
}
function addAll()
{
	DWRUtil.removeAllOptions('typeSelId');
	DWRUtil.removeAllOptions('typeNoSelId');
	DWRUtil.addOptions("typeSelId", allOption, 'value', 'textValue');
}

function removeAll()
{
	DWRUtil.removeAllOptions('typeSelId');
	DWRUtil.removeAllOptions('typeNoSelId');
	DWRUtil.addOptions("typeNoSelId", allOption, 'value', 'textValue');
}

function submitClose(){
	flag=true;
 	window.close();
}
function beforeCloseWindow(){
	var f = document.form1;
	var opeOption =[];
	if(flag){
		var valueFrom='right';
		if(window.showModalDialog==null){
			valueFrom=window.opener.objWindow.valueFrom;
		}else{
			valueFrom=window.dialogArguments.valueFrom;
		}
		if(valueFrom=='left'){
			for(var k=0;k<f.s1.options.length;k++){  
 				opeOption[opeOption.length] = {value:f.s1.options[k].value,textValue:f.s1.options[k].innerHTML};
 			}
		}else{
			for(var k=0;k<f.s2.options.length;k++){  
 				opeOption[opeOption.length] = {value:f.s2.options[k].value,textValue:f.s2.options[k].innerHTML};
 			}
		}	
	}else{
		opeOption=window.dialogArguments.selOption||window.opener.objWindow.selOption;
	}
	 if(window.showModalDialog){
 		 window.returnValue = opeOption;
	 }
}